<?php
/**
 * JoiGallery - image gallery component for Joostina
 *
 * Шаблон вывода категории
 *
 * @version 1.0 alpha 12
 * @package JoiGallery
 * @subpackage	View
 * @filename artisnova-category-view.php
 * @author Alexej Pozdnjakov
 * @copyright Woodell Web Works
 * @license see license.txt
 *
 **/
defined('_VALID_MOS') or die();

//Подключаем CSS-файл шаблона
//$mainframe->addCSS(JPATH_SITE.'/components/com_joigallery/view/css/default.css');

    if ((!$cat->id) || ($cat->id > 0 && $cat->published < 1 && !$params->_access->allow_me('view_unpub_cat', $my->gid))) { ?>
    	<div class="error"><?php echo $params->_access->error('view_unpub_cat'); ?></div>	
	<?php return; } ?>

	<?php if(!$params->_access->allow_me('view_cat', $my->gid)){ ?>
		<div class="error"><?php echo $params->_access->error('view_cat'); ?></div>	
	<?php return; } ?>
    
    
    <?php
        //Тэги
        //$tags = new joiTags($mainframe, 'com_joigallery');
        //$tags->display_group_tags($photos);    
    ?>

<div class="joi_gallery"><!--joi_gallery-->
  <div class="joi_gallery_category"><!--joi_gallery_category-->

    <?php
    if ($params->cat_pathway)
         echo '<div class="joi_gallery_pathway">'.mosPathWay().'</div>'; 
    ?>

    <div class="componentheading">
      <div class="buttons fr">
        <?php echo HTML_joigallery::buttonAddCat($cat, $params); ?>
        <?php echo HTML_joigallery::buttonEditCat($cat, $params);?>
        <?php echo HTML_joigallery::buttonDeleteCat($cat, $params);?>
        <?php echo HTML_joigallery::buttonUploadPhoto($cat, $params);?>
      </div>
      <?php if ($params->get('template_cat_title')) { ?>
                <h1><?php echo $cat->name; ?></h1>
      <?php }
            else echo '<div class="clrpx">&nbsp;</div>';
      ?>
    </div>
    <div class="clrpx">&nbsp;</div>

    <div class="description">
      <?php echo $cat->description;?>
    </div>
    <div class="clrpx">&nbsp;</div>
    
    <!--Подкатегории-->
    <?php if($subcats && count($subcats) > 0){ ?>
    <div class="catlist subcat_block<?php //echo ($params->get('cat_view_subcats') ? '' : ' subcat_block'); ?>">

      <!--Заголовок подкатегорий-->
      <div class="clrpx">&nbsp;</div>
      <?php if($params->get('template_cat_subcats_title') || $params->get('template_cat_subcats_desc') ) {?>
        <div class="txt_subcats">
          <?php if($params->get('template_cat_subcats_title') ) : ?>
              <?php echo '<div class="title_subcats">'.$params->get('template_cat_subcats_title').'</div>'; ?>
          <?php endif;?>
          <?php if($params->get('template_cat_subcats_desc') ) : ?>
              <?php echo '<div class="desc_subcats">'.$params->get('template_cat_subcats_desc').'</div>'; ?>
          <?php endif;?>
        </div>
      <?php };?>

   

      <div class="thumbnails">
        <?php for($i = 0,$n = count($subcats); $i < $n; $i++) {
          $subcat  = $subcats[$i];
          $subcat_photo = $params->get('template_cat_subcats_photo_random')
                        ? $cat->get_random_photo($subcat->id)
                        : $subcat->photo_path;
          $link = joiGalleryHelper::get_cat_link($subcat->id, $params);
          $img_src = joiGalleryHelper::get_thumb($subcat_photo, $params, $mainframe, $subcat->id);
          $count   = $imgs->get_count_photos($subcat->id);
          //$count   = $imgs->get_count_photos_with_subcats($subcat->id);
        ?>

        <!--Подкатегория-->
        <div class="thumbnail<?php echo ($subcat->published < 1 ? ' unpublished' : ''); ?>">
          <div class="r">

            <?php if($params->get('cat_view_subcats_thumb', 1) ) : ?>
              <a class="thumb" href="<?php echo $link; ?>">
                <img src="<?php echo $img_src; ?>"
                     border="0"
                     alt="<?php echo $subcat->photo_name; ?>"
                     width="<?php echo $params->thumbnail_width;?>" />
              </a>
            <?php endif;?>

            <?php if($params->get('cat_name_cat_view', 1) ) : ?>
                    <h2><a class="link6" href="<?php echo $link; ?>"><?php echo $subcat->name; ?></a></h2>
            <?php endif;?>

            <?php if($params->get('cat_desc_cat_view', 1) ) : ?>
              <?php echo '<div class="subcat_desc">'.$subcat->description.'</div>'; ?>
            <?php endif;?>

            <?php if($params->get('template_cat_subcats_photo_count', 1) ) : ?>
                <?php echo '<div class="subcat_img_count">'._C_JOIGALLERY_PUBLISHED.': '.$count.'</div>'; ?>
            <?php endif;?>

          </div>
        </div>
        <!--/Подкатегория -->

      <?php } ?>
      </div>

    </div>
    <?php } ?>
    <!--/Подкатегории-->

    <!--Область вывода плагинов:BEGIN-->
    <?php $plugins->load('displayFancyboxGallery'); ?>    
    <!--Область вывода плагинов:END-->

    <!--Изображения-->
      <?php  if($photos && count($photos) > 0){  ?>
      <div class="photos">

        <div class="thumbnails">
          <?php foreach($photos as $photo) {
            
//            $src_path = JPATH_SITE.$params->thumbnail_path;
//            $src_path = file_exists(JPATH_BASE.$params->thumbnail_path.'/'.$photo->path)
//                      ? $src_path.'/'.$photo->path : $src_path.'/'.$photo->cid.'/noimage.jpg';
            if($params->get('template_cat_use_lightbox')) {
                $link   = JPATH_SITE.$params->original_path.'/'.$photo->path;
                $target = 'target="_blank"';
                $class  = ' middle_thumb';
                $rel    = 'rel="group_'.(int)$cat->id.'"';
            } 
            else {
                $link = sefRelToAbs('index.php?option='
                        .$params->_option.'&amp;act=photos&amp;cid='
                        .$photo->id.'&amp;Itemid='.$params->_Itemid);
                $target = '';
                $class  = '';
                $rel    = '';
            }
            //Ссылка на страницу изображения при клике на название
            $link_full = sefRelToAbs('index.php?option='
                        .$params->_option.'&amp;act=photos&amp;cid='
                        .$photo->id.'&amp;Itemid='.$params->_Itemid);

            $title = '';
            $src_path = JPATH_SITE.$params->thumbnail_path;
            if (file_exists(JPATH_BASE.$params->thumbnail_path.'/'.$photo->path)) {
                $src_path = $src_path.'/'.$photo->path;
                if ($photo->description) {
                    $title = mosHTML::cleanText($photo->description);
                    $title = Text::character_limiter($title, 100, '...');
                    $title = 'title="'.$photo->description.'"';
                }
                //$title = 'title="'.$photo->name.'"';
            }
            else {
                $src_path = $src_path.'/'.$photo->cid.'/noimage.jpg';
                $title = 'title="'._C_JOIGALLERY_MSG_IMG_NOT_FOUND_THUMB.'"';
                $class = $params->get('template_cat_use_lightbox') ? ' noimage middle_thumb' : ' noimage';
                if (!file_exists(JPATH_BASE.$params->original_path.'/'.$photo->path)) {
                    $link   = $link_full;
                    $rel    = '';
                    $target = '';
                    $class  = ' noimage';
                }
            }
            
          ?>
        
          <!--Изображение-->
          <div class="thumbnail<?php echo ($photo->state < 1 ? ' unpublished' : ''); ?>">
            <div class="r">

              <a class="thumb<?php echo $class; ?>" <?php echo $target; ?> <?php echo $rel; ?> href="<?php echo $link; ?>" <?php echo $title; ?>>
                <img src="<?php echo $src_path; ?>"
                     border="0"
                     alt="<?php echo $photo->name; ?>"
                     <?php echo $title; ?>                     
                     width="<?php echo $params->thumbnail_width;?>"
                     height="<?php echo $params->thumbnail_height;?>" />
                </a>

              <?php if($params->get('image_name_cat_view', 1)): ?>
                        <h3>
                          <a class="link6" 
                             href="<?php echo $link_full; ?>"
                             title="<?php echo _SHOW.' '.$photo->name;?>">
                           <?php  echo $photo->name; ?>
                          </a>
                        </h3>
              <?php endif;?>

              <?php
              if($params->get('image_desc_cat_view', 0) ) :
                  echo '<div class="photo_desc">'.$photo->description.'</div>';
              endif;?>

              <?php
              if($params->get('image_rate_cat_view', 1) ) :
                  $_MAMBOTS->call('onRating', $photo, $params);
              endif;
              ?>

              <?php
              if($params->get('comments_cat_view', 1) ) :
                  $comments_count = JComments::getCommentsCount($photo->id, 'com_joigallery');
                  echo _C_JOIGALLERY_COMMENTS.': '. $comments_count;
              endif;
              ?>

              <?php
              //Тэги
              //echo $tags->print_tags($photo->id);
              ?>
            </div><!--r -->
          </div><!--thumbnail -->
          <!--/Изображение-->

          <?php } ?>
      </div><!--thumbnails -->

      <?php //Постраничная навигация
      $link = 'index.php?option='.$params->_option.'&amp;act=categories&amp;cid='
              .$cat->id.'&amp;Itemid='.$params->_Itemid;
      echo $pageNav->writePagesLinks($link); ?>

      </div>
      <?php } ?>
      <!--/Изображения-->


  </div><!--/joi_gallery_category-->
  
  <?php //echo 'Ключевые слова: '.$subcat->params; ?>
  
</div><!--/joi_gallery-->